﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Data.Services;
using System.Globalization;

namespace AstoriaPlus
{
	/// <summary>
	/// Helper methods to throw proper exceptions for a <see cref="HttpStatusCode"/> from the service.
	/// </summary>
	public static class HttpStatusCodeExtensions
	{
		/// <summary>
		/// Throws a <see cref="DataServiceException"/> with the given status code and message (or format string and format arguments).
		/// </summary>
		public static void Throw(this HttpStatusCode status, string messageOrFormat, params object[] args)
		{
			if (args != null && args.Length != 0)
				throw new DataServiceException((int)status, string.Format(CultureInfo.CurrentCulture, messageOrFormat, args));
			else
				throw new DataServiceException((int)status, messageOrFormat);
		}
	}
}
